const express = require(`express`)
const fun_sys_table_list = require("../../modules/fun/fun_sys_table_list");
const router = express.Router()
router.post(`/`, (req, res, next) => {
    res.json({
        status: 0,
        data: `表处理`
    })
})
router.post('/insert',async function (req, res,next){
    try {
        let getByName = await fun_sys_table_list.getByName(req.query);
        if(getByName.length>0){
            throw new Error("已经存在该数据表");
        }
        let insert =await  fun_sys_table_list.insert(req.query);
        res.send({
            status:0,data:insert
        })
    }catch (e) {
        next(e)
    }
});
router.post('/getList',async function (req, res,next){
    try {
        let getByName = await fun_sys_table_list.getList(req.query);
        res.send({
            status:0,data:getByName
        })
    }catch (e) {
        next(e)
    }
});
router.post('/delete',async function (req, res,next){
    try {
        let getById = await fun_sys_table_list.getById(req.query);
        if(getById.length<=0){
            throw new Error("数据不存在");
        }
        let _delete = await fun_sys_table_list.delete(req.query);
        res.send({
            status:0,data:_delete
        })
    }catch (e) {
        next(e)
    }
});
router.post('/update',async function (req, res,next){
    try {
        let getById = await fun_sys_table_list.getById(req.query);
        if(getById.length<=0){
            throw new Error("数据不存在");
        }
        let update = await fun_sys_table_list.update(req.query);
        res.send({
            status:0,data:update
        })
    }catch (e) {
        next(e)
    }
});
module.exports = router;